var ev = (function(){
    /**
     * 事件委托
     * @param {当前宿主} element 要绑定事件的宿主
     * @param {事件类型} eventType 
     * @param {点击到的元素选择器} selector 
     * @param {执行的函数} fn 
     */
    var _delegate = function(element, eventType, selector, fn){
        element.addEventListener(eventType, function(ev){
            var el = ev.target;
            // console.log(el)
            // console.log(el.matches)
            try {
                while (!el.matches(selector)) {
                    el = el.parentNode;
                    if (element == el) {
                        el = null;
                        break;
                    }
                }
                el && fn.call(el, ev, el);
            } catch (error) {
                // 防止有document的情况
                // console.log(el);
            }
        })
    }

    return {
        delegate: _delegate
    }
})()